package com.example.chessmigame;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class ControlActivity extends AppCompatActivity {

    EditText countdown,n1,n2,n3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_control);

        n1 = findViewById(R.id.n1);
        n2 = findViewById(R.id.n2);
        n3 = findViewById(R.id.n3);
        countdown = findViewById(R.id.countdown);

        //读取之前保存的记录
        SharedPreferences setting = getSharedPreferences("GameSettings",MODE_PRIVATE);

        String countdown1 = setting.getString("countdown", "");
        String n11 = setting.getString("n1", "");
        String n21 = setting.getString("n2", "");
        String n31 = setting.getString("n3", "");

        this.countdown.setText(countdown1);
        this.n1.setText(n11);
        this.n2.setText(n21);
        this.n3.setText(n31);
    }

    public void onclick(View v){//存入数据
        SharedPreferences setting = getSharedPreferences("GameSettings",0);
        SharedPreferences.Editor editor = setting.edit();

        String n1_str = this.n1.getText().toString();
        String n2_str = this.n2.getText().toString();
        String n3_str = this.n3.getText().toString();
        String countdown_str = this.countdown.getText().toString();

        editor.putString("countdown",countdown_str);
        editor.putString("n1",n1_str);
        editor.putString("n2",n2_str);
        editor.putString("n3",n3_str);

        editor.commit();

        Intent intent=new Intent(ControlActivity.this,GameActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

}